package ControlLayer;
import java.util.ArrayList;
import ModelLayer.*;//importing layer package


public class AddressController
{
    private  AddressBook addressBook; // declare container

    public AddressController()
    {
       addressBook = AddressBook.getInstance();
    }
    
    public Person getPerson(String id)
    {
        return addressBook.findPerson(id);
    }
    
    public String printPerson(String id)
    {
       return addressBook.findPerson(id).toString();
    }
    
    public void createPerson(String id, String name, String address, String postalCode, String city, String phone)
    {
        if(getPerson(id)!=null){
            System.out.println("Person with ID: "+id+" already exists.");
        }else{
            //creates a Person object and stores it in the container
            addressBook.addPerson(id, name, address, postalCode, city, phone); 
        }
    }
    
    public void deletePerson(String id)
    {
            addressBook.deletePerson(id);
    }
    
    public void updatePerson(String id, String name, String address, String postalCode, String city, String phone)
    {
        addressBook.updatePerson(getPerson(id),  name,  address,  postalCode,  city,  phone );
    }
    
    public ArrayList<Person> listAllPersons()
    {
         if(addressBook.getPerson().isEmpty()){
               System.out.println("Address book is empty.");
         }
          return addressBook.getPerson();
    }
}
